package com.sgb.kjwl.viewmodel.pick;

import androidx.lifecycle.ViewModel;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.view.ui.activity.pick.PickExpertEditActivity;
import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.entity.PickExpertDetailEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.List;

/**
 *
 */
public class PickExpertEditModel extends ViewModel {

    //专家库发布所属类别列表
    public void getCategoryTypeList(PickExpertEditActivity activity) {
        APIManager.getInstance().getPickAPI().getCategoryTypeList().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setCategoryType(data.getData());
                }
            }
        });
    }

    //专家库发布执业资格列表
    public void getCertificateList(PickExpertEditActivity activity) {
        APIManager.getInstance().getPickAPI().getCertificateList().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setCertificateList(data.getData());
                }
            }
        });
    }

    //专家库发布评标专业列表
    public void getAllMajorCategoryList(PickExpertEditActivity activity) {
        APIManager.getInstance().getPickAPI().getAllMajorCategoryList().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setAllMajorCategoryList(data.getData());
                }
            }
        });
    }

    //专家库发布专家职称列表
    public void getProfessionList(PickExpertEditActivity activity) {
        APIManager.getInstance().getPickAPI().getProfessionList().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setProfessionList(data.getData());
                }
            }
        });
    }

    //地址信息
    public void getAddressModel(PickExpertEditActivity activity) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getAddressEntityCityList().enqueue(new ICallBack<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>>() {
            @Override
            public void onSuccess(BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null && data.getData() != null && data.getData().size() > 0) {
                    activity.setAddressList(data.getData());
                }
            }
        });
    }


    //编辑专家(增加、修改)
    public void edit(PickExpertEditActivity activity, PickExpertDetailEntity pickExpertDetailEntity) {
        APIManager.getInstance().getPickAPI().edit(pickExpertDetailEntity).enqueue(new ICallBack<BaseEntity<BaseEntity>>() {
            @Override
            public void onSuccess(BaseEntity<BaseEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setEditData("提交成功");
                }else{
                    activity.setEditData(data.getData().getData().toString());
                }
            }
        });
    }

    //详情
    public void detail(PickExpertEditActivity activity,String no) {
        APIManager.getInstance().getPickAPI().detail(no).enqueue(new ICallBack<BaseEntity<PickExpertDetailEntity>>() {
            @Override
            public void onSuccess(BaseEntity<PickExpertDetailEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setDetailsData(data.getData());
                }
            }
        });
    }
}
